package com.rj.util;

import cn.hutool.core.codec.Morse;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.Validator;

import java.util.Set;

/**
 * 实体校验工具
 *
 * @author YFX_RANLUBO
 * @date 2022/10/26 18:55
 **/
public class ValidationUtils {
    private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();

    /**
     * 检查参数信息
     *
     * @param bean   实体
     * @param groups 校验组
     * @return 错误信息
     */
    public static String validate(Object bean, Class<?>... groups) {
        Set<ConstraintViolation<Object>> violations = validator.validate(bean, groups);
        if (VerifyUtils.notEmpty(violations)) {
            StringBuilder stringBuilder = new StringBuilder();
            violations.forEach(
                    e -> stringBuilder.append(e.getMessage()).append(";"));
            return stringBuilder.substring(0, stringBuilder.length() - 1);
        }
        return null;
    }

    public static void main(String[] args) {
        int start = 0x4E00;
        int end = 0x9FA5+1;

        for (int i = start; i <= end; i++) {
            char ch = (char) i;
            System.out.println(ch);
        }
    }
}
